package com.mhkj.common.util;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mics.core.common.componet.ResponseMessage;
import com.mics.core.common.util.ftp.FtpUtil;
import com.mics.core.system.base.controller.BaseController;
import com.mics.core.system.base.entity.FileEntity;
import com.mics.core.system.base.service.FileService;

@Controller
@RequestMapping("/fileCommon")
public class FileController extends BaseController<FileEntity>{
	

	@Resource
	private FileService fileservice;
	/**
	 * 查询所有的计划节点
	 * 
	 * @author mics
	 * @date 2018年7月11日
	 * @version 1.0
	 */
	@RequestMapping("/loadFileList")
	@ResponseBody
	public List<FileEntity> listAll(long tableId,String tableName) {
		List<FileEntity> listFile = fileservice.listFileByTableIdAndName(tableId, tableName);
		return listFile;

	}
	/**
	 * 删除
	 * 
	 * @author wk
	 * @date 2018年9月10日
	 * @version 1.0
	 */
	@RequestMapping("/del")
	@ResponseBody
	public ResponseMessage del(FileEntity fileEntity) {
		String message = fileservice.del(fileEntity);
		try {
			FtpUtil.deleteFile(fileEntity.getFileUrl());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return ResponseMessage.createMessage("ok".equals(message), message);
	}

}
